package cn.edu.nwsuaf.examcenter.service.serviceImpl;


import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import cn.edu.nwsuaf.examcenter.model.PageModel;
import cn.edu.nwsuaf.examcenter.pojo.Grade;
import cn.edu.nwsuaf.examcenter.service.GradeService;

@Service(value="gradeService")
public class GradeServiceImpl extends BaseServiceImpl<Grade> implements GradeService{
	
	/****
	 * 添加年级
	 * @param grade
	 * @return
	 */
	public String addGrade(Grade grade){
		super.saveData(grade);
		return "success";
	}
	
	public String deleteGrade(String gradeNo){
		super.deleteData(super.loadById(Grade.class, gradeNo));
		return "success";
	}
	public String deleteGradeList(String array){
		String[] gradeNos = array.split(",");
		List<Grade> list = new ArrayList<>();
		for(String gradeNo:gradeNos){
			list.add(super.loadById(Grade.class, gradeNo));
		}
		super.deleteDataList(list);
		return "success";
	}
	/****
	 * 搜索年级
	 */
	public void loadGrade(ModelMap modelMap){
		PageModel<Grade> gradeModel = new PageModel<>();
		List<Grade> list = super.findAll(Grade.class);
		gradeModel.setTotalrows(list.size());
		gradeModel.setList(list);
		modelMap.addAttribute("gradeModel",gradeModel);
	}

	@Override
	public void exportGrade(HttpServletRequest request, HttpServletResponse response) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public List<Grade> jsonLoadGrade(String majorNo) {
		// TODO Auto-generated method stub
		String[] param={majorNo};
		return super.findAll("FROM Grade as grade where grade.major.majorNo=?", param);
	}
	
	
}
